package com.nxk.modules.content.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.nxk.modules.content.entity.ConNews;
import com.nxk.modules.content.entity.ConNotice;
import com.nxk.modules.content.service.ConNewsService;
import com.nxk.modules.core.entity.BaseEntity;
import com.nxk.modules.exception.ResultEntity;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/web/api/news")
public class NewsApiController {

    @Autowired
    private ConNewsService conNewsService;

    @PostMapping("/newsDetail")
    public ResultEntity newsDetail(ConNews conNews){
        QueryWrapper<ConNews> queryWrapper = new QueryWrapper<>();
        if(StringUtils.isNotBlank(conNews.getId())){
            queryWrapper.eq("id",conNews.getId());
        }
        if (StringUtils.isNotBlank(conNews.getNewsType())){
            queryWrapper.eq("news_type",conNews.getNewsType());
        }
        queryWrapper.eq("status", BaseEntity.STATUS_NORMAL);
        queryWrapper.orderByAsc("sort");
        queryWrapper.last("limit 10");
        List<ConNews> list = conNewsService.list(queryWrapper);
        return ResultEntity.success(list);
    }

}
